import { splitVendorChunkPlugin, type UserConfig } from 'vite'
import viteCompression from 'vite-plugin-compression'

export default (): UserConfig => {
  return {
    plugins: [
      splitVendorChunkPlugin(),
      viteCompression({
        verbose: true,
        disable: false,
        threshold: 10240,
        algorithm: 'gzip',
        ext: '.gz'
      })
    ],
    // https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
    build: {
      // Tauri supports es2021
      target: process.env.TAURI_PLATFORM === 'windows' ? 'chrome105' : 'safari13',
      minify: !process.env.TAURI_DEBUG ? 'esbuild' : false,
      sourcemap: false
    }
  }
}

/**
 *
 * import visualizer from 'rollup-plugin-visualizer'
 * visualizer({
 *   open: true
 * })
 *
 */
